using System.Collections;
using UnityEngine;

public class OnChargeContinuous : OnChargeObj
{
	private new Transform start;

	private Transform target;

	private Vector3 _endPos;

	private Vector3 StartPos
	{
		get
		{
			if (start == null)
			{
				return Vector3.zero;
			}
			return start.position;
		}
	}

	private Vector3 EndPos
	{
		get
		{
			if (target == null)
			{
				return _endPos;
			}
			return target.position;
		}
	}

	public void SetTarget(Transform target)
	{
		start = start;
	}

	public void SetStart(Transform start)
	{
		this.start = start;
	}

	public void SetEnd(Vector3 end)
	{
		_endPos = end;
	}

	public override IEnumerator UpdateCharge()
	{
		base.transform.SetParent(null);
		Object.Destroy(base.gameObject, lifeTime);
		LineRenderer lineRenderer = GetComponent<LineRenderer>();
		while (true)
		{
			ChangeLine(lineRenderer);
			yield return new WaitForEndOfFrame();
		}
	}

	private void ChangeLine(LineRenderer line)
	{
		int num = 10;
		line.SetVertexCount(num);
		Vector3 normalized = (EndPos - StartPos).normalized;
		float magnitude = (EndPos - StartPos).magnitude;
		float num2 = magnitude / (float)num;
		for (int i = 0; i < num - 1; i++)
		{
			line.SetPosition(i, StartPos + normalized * num2 * i + Random.insideUnitSphere / TitanSpawner.instance.currentTitan.TargetDetector.coef);
		}
		line.SetPosition(num - 1, EndPos);
	}
}
